package cn.com.lyb.mrs.controller;

import cn.com.lyb.mrs.dto.requestDTO.JobActionResquest;
import cn.com.lyb.mrs.dto.requestDTO.JobRequest;
import cn.com.lyb.mrs.dto.requestDTO.TenantRequest;
import cn.com.lyb.mrs.service.ExecService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;

@RequestMapping("/v1")
@RestController
@Api(tags = "测试mrs")
public class TestController {

    private static final Logger logger = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private ExecService execService;


    @ApiOperation(value = "创建应用")
    @PostMapping("/saveTenant")
    public void saveTenant(@RequestBody TenantRequest tenantRequest) throws NoSuchAlgorithmException, KeyManagementException {
        execService.saveTenant(tenantRequest);
    }

    @ApiOperation(value = "上传flinkJar")
    @PostMapping("/uploadJar")
    public void uploadJar(String tenantId, String jarPath) throws NoSuchAlgorithmException, KeyManagementException {
        File file = new File(jarPath);
        execService.uploadJar(tenantId, file);
    }

    @ApiOperation(value = "创建作业")
    @PostMapping("/saveWork")
    public void saveWork(@RequestBody JobRequest jobRequest) throws NoSuchAlgorithmException, KeyManagementException {
        execService.saveWork(jobRequest);
    }


    @ApiOperation(value = "启动作业")
    @PostMapping("/actionWork")
    public void actionWork(@RequestBody JobActionResquest actionResquest) throws NoSuchAlgorithmException, KeyManagementException {
        execService.actionWork(actionResquest);
    }

}
